package com.raowb.common.base.controllers;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;

/**
 * 
 * @Description:
 * @author: raowb
 * @date 2018年8月6日
 */
public class BaseController
		extends com.ruoyi.common.core.controller.BaseController {
	// protected Logger logger = LoggerFactory.getLogger(getClass());

	/**
	 * 响应请求分页数据
	 */
	protected TableDataInfo getDataTable(IPage<?> page) {
		List<?> list = page.getRecords();

		TableDataInfo rspData = new TableDataInfo();
		rspData.setCode(HttpStatus.SUCCESS);
		rspData.setMsg("查询成功");
		rspData.setRows(list);
		rspData.setTotal(page.getTotal());
		return rspData;
	}

	/**
	 * 
	* @Title: wrapQueryWrapper
	* @Description: 封装查询参数
	* @param entity
	* @return    设定文件
	* @return QueryWrapper<T>    返回类型
	* @throws
	 */
	protected <T> QueryWrapper<T> getQueryWrapper(T entity) {
		PageDomain pageDomain = TableSupport.buildPageRequest();		
		return new QueryWrapper<>(entity).orderBy(true,"asc".equals(pageDomain.getIsAsc()),pageDomain.getOrderByColumn());
	}

	/**
	 * 
	 * @Title: getPage @Description:获取分页 @return 设定文件 @return IPage<T>
	 * 返回类型 @throws
	 */
	protected <T> IPage<T> getPage() {
		PageDomain pageDomain = TableSupport.buildPageRequest();
		return new Page<>(pageDomain.getPageNum() == null?1:pageDomain.getPageNum(), pageDomain.getPageSize() == null?10:pageDomain.getPageSize());
	}

}
